<template>
  <div class="app-container">
    <el-button type="primary" icon="el-icon-plus" circle @click="dialogVisible=true" />
    <el-button icon="el-icon-search" circle @click="initList()" />
    <el-table :data="list" row-key="id" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="#" width="65">
        <template slot-scope="scope">
          <span>{{ scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="页面变量" width="260">
        <template slot-scope="scope">
          <span>{{ scope.row.pagekey }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="页面名称" width="260">
        <template slot-scope="scope">
          <span>{{ scope.row.pageName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" width="220">
        <template slot-scope="scope">
          <span>{{ scope.row.created|parseTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="$api.go('/design/page-detail',{id:scope.row.id})" />
          <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <pagination v-if="query.total!=0" :total="query.total" :page.sync="query.page" :limit.sync="query.size" @pagination="initList" />



    <el-dialog title="修改添加页面" :visible.sync="dialogVisible" @close="form={}" width="30%">
      <el-form :model="form" label-width="80px">
        <el-form-item label="页面变量">
          <el-input v-model="form.pagekey"></el-input>
          <span style="color: red">页面属性必须是唯一的</span>
        </el-form-item>
        <el-form-item label="页面名称">
          <el-input v-model="form.pageName"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handlerSubmit">确定</el-button>
          <el-button @click="dialogVisible=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data () {
    return {
      dialogVisible:false,
      list: [],
      query: { page: 1, size: 20, total: 0 },
      form:{}
    }
  },
  created () {
    this.initList()
  },
  methods: {
    initList() {
      this.$api.get('/api/design/page', this.query).then(res => {
        this.list = res.data;
        this.query.total = res.total;
      })
    },
    //添加新的页面
    handlerSubmit(){
      this.$api.put('/api/design/page',{},this.form).then(res=>{
        this.dialogVisible=false,
          this.initList();
      })
    },
    handleDelete(row){
      this.$api.deleteConfirm('/api/design/page',{id:row.id}).then(res=>{
        this.initList();
      })
    }
  }
}
</script>
